<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>修改密码</title>
	<link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all" />
	<link rel="stylesheet" th:href="@{/css/public.css}" media="all" />
</head>
<body class="background-info">
<!--<h2 style="padding: 20px 20px"><b><a href="/"> 返回首页 </a></b></h2>-->
<form class="layui-form layui-row changePwd form-container" method="post" id="formChange" lay-filter="formChange">
	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
		<div style="text-align: center"><img style="text-align: center;width: 400px; height: auto;" th:src="@{/images/changepassword.png}"></div>
		<div class="layui-input-block pwdTips"><span style="color: red"><strong>若是初始密码请输入“123456”，新密码必须两次输入一致才能提交</strong></span></div>
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="hidden" name="id" th:value="${session.user.id}">
				<input type="text" value="" id="name" th:value="${session.user.username}" disabled  class="layui-input layui-disabled" autocomplete="false">
			</div>
		</div>
		<!-- 隐藏的虚拟密码字段, 引导浏览器填充 -->
		<div style="display: none;">
			<input type="password" name="fakePassword" autocomplete="current-password">
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">旧密码</label>
			<div class="layui-input-block">
				<input type="password" value="" id="oldPassword" name="password" placeholder="请输入旧密码" lay-verify="required" class="layui-input pwd" autocomplete="new-password" readonly onfocus="this.removeAttribute('readonly')">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input type="password" value="" id="newPwdOne" name="newPwdOne" placeholder="请输入新密码" lay-verify="required|newPwd"  class="layui-input pwd" autocomplete="false">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-block">
				<input type="password" value="" id="newPwdTwo" name="newPwdTwo" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd" autocomplete="false">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="changePwd">立即修改</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/page/user/user.js}"></script>

<script type="text/javascript">
	layui.use(['jquery','form','layer'],function () {
		var $ = layui.jquery;
		var form = layui.form;
		var layer = layui.layer;


		form.on("submit(changePwd)",function (data) {
		    var name = $("#name").val();
            // var oldPassword = $("#oldPassword").val();
            // var newPwdOne = $("#newPwdOne").val();
            // var newPwdTwo = $("#newPwdTwo").val();
            layer.confirm('你确定要修改【' + name + '】这个用户的密吗？', {icon: 3, title: '提示'}, function (index) {
				$.post('/user/changePassword',data.field,function (res) {
					layer.msg(res.msg);
					if (res.code === 200) { // 假设服务器返回的成功状态码是 200
						layer.msg('密码修改成功，3 秒后将返回登录界面', { icon: 1, time: 3000 });
						setTimeout(function () {
							window.location.href = '/logout'; // 跳转到登录界面
						}, 3000);
					}
				});
				layer.close(index);

            });
        	return false;
		});

    });
</script>

</body>
</html>